
#define PI 3.1415926535

float sdCircle( vec2 p, float r ) {
    return length(p) - r;
}

float sdBox(in vec2 p,in vec2 b)
{
    vec2 d=abs(p)-b;
    return length(max(d,0.))+min(max(d.x,d.y),0.);
}

/* 2D Rotation */
mat2 rotation2d(float angle) {
    float s = sin(angle);
    float c = cos(angle);

    return mat2(
        c, -s,
        s, c
    );
}

vec2 rotate(vec2 v, float angle) {
  return rotation2d(angle) * v;
}
/* 2D Rotation */

void main() {
    // 注意 gl_FragCoord 是原始的像素坐标值, 不是uv坐标(0~1);
    vec2 uv = (gl_FragCoord.xy - 0.5*iResolution.xy)/iResolution.xx;
    uv -= vec2( 0.1, 0.3 );                 // 平移
    // uv *= vec2( 1.0, 2.0 );                 // 非等比缩放 X轴1倍 Y轴两倍
    // uv = rotate( uv, PI/11.0);              // 非等比缩放会导致在旋转之后图像形变
    float speed = 0.2;
    uv = rotate( uv, (iTime)*speed );
    float d = sdBox(uv, vec2(0.2, 0.4));
    float c = smoothstep( 0.0, 0.01, d );
    gl_FragColor = vec4( vec3(c), 1.0 );
}